﻿using ApprovalTests;
using ApprovalTests.Reporters;
using DZParallelLib.DZImage;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Threading.Tasks;

namespace DZParallelLib.Test.DZImage
{
    [TestClass]
    public class DZRenderedImageTest
    {
        [TestMethod]
        [ExpectedException(typeof(FileNotFoundException))]
        public void TestLoadBadImage()
        {
            var dz = new DZRenderedImage(new FileInfo("bogus.xml"));
        }

        [TestMethod]
        [DeploymentItem("DZImage1", "DZImage1")]
        public void TestLoadSimpleImageBasicProperties()
        {
            var dz = new DZRenderedImage(new FileInfo(@"DZImage1\sc\vnpzyair.xml"));
            Assert.IsNotNull(dz, "rendered image");
            Assert.AreEqual((ulong)256, dz.TileSize, "tile size");
            Assert.AreEqual((ulong)696, dz.Width, "Image width");
            Assert.AreEqual((ulong)472, dz.Height, "Image width");
            Assert.AreEqual((ulong)1, dz.Overlap, "Image overlap");
        }

        [TestMethod]
        [DeploymentItem("DZImage1", "DZImage1")]
        [UseReporter(typeof(TortoiseImageDiffReporter))]
        public void TestLoadImageOfSmallSize()
        {
            var dz = new DZRenderedImage(new FileInfo(@"DZImage1\sc\vnpzyair.xml"));
            var img = dz.GetClosestBitmap(256).Result;
            Assert.AreEqual(256 + 92, img.Width, "bm width");
            Assert.AreEqual(236, img.Height, "bm height");
            Approvals.VerifyFile(img.AsImageFile());
        }

        [TestMethod]
        [DeploymentItem("DZImage1", "DZImage1")]
        public async Task TestLoadImageOfTooBigSize()
        {
            var dz = new DZRenderedImage(new FileInfo(@"DZImage1\sc\vnpzyair.xml"));
            var img = await dz.GetClosestBitmap(5000);
            Assert.AreEqual(696, img.Width, "width");
            Assert.AreEqual(472, img.Height, "height");
        }

        [TestMethod]
        [DeploymentItem("DZImage1", "DZImage1")]
        public void TestImageLevelCalc()
        {
            var dz = new DZRenderedImage(new FileInfo(@"DZImage1\sc\vnpzyair.xml"));
            Assert.AreEqual((uint)11, dz.NumberOfLevels);
        }

    }
}
